import dotenv
import weaviate
from langchain_openai import OpenAIEmbeddings
from langchain_weaviate import WeaviateVectorStore
from weaviate.auth import AuthApiKey


texts = [
    "笨笨是一只很喜欢睡觉的猫咪",
    "我喜欢在夜晚听音乐，这让我感到放松。",
    "猫咪在窗台上打盹，看起来非常可爱。",
    "学习新技能是每个人都应该追求的目标。",
    "我最喜欢的食物是意大利面，尤其是番茄酱的那种。",
    "昨晚我做了一个奇怪的梦，梦见自己在太空飞行。",
    "我的手机突然关机了，让我有些焦虑。",
    "阅读是我每天都会做的事情，我觉得很充实。",
    "他们一起计划了一次周末的野餐，希望天气能好。",
    "我的狗喜欢追逐球，看起来非常开心。",
]
metadatas =[
    {"page": 1},
    {"page": 2},
    {"page": 3},
    {"page": 4},
    {"page": 5},
    {"page": 6},
    {"page": 7},
    {"page": 8},
    {"page": 9},
    {"page": 10},
]
dotenv.load_dotenv()

client = weaviate.connect_to_weaviate_cloud(
    cluster_url="https://ch1cjmeqwksbbi0taqj4g.c0.asia-southeast1.gcp.weaviate.cloud",
    auth_credentials=AuthApiKey("bjg3NHRXdlJ3K0xvT2d1UV9xdzVEbG9SQ3p2NUR6S0EvSWhtS1JtV09laFpOQTdadzFSTmFuakJxUlJJPV92MjAw")
)
embedding = OpenAIEmbeddings(model="text-embedding-3-small")
db = WeaviateVectorStore(client= client, index_name="DataSetText", text_key="text", embedding=embedding)


ids = db.add_texts(texts=texts,metadatas=metadatas)
#print(ids)
# 相似性搜索
search_results = db.similarity_search_with_score("请问有一只猫叫笨笨吗？")
for  one in search_results:
    print(one)
client.close()
